/**
 * Definition for singly-linked list. */
  struct ListNode {
     int val;
      ListNode *next;
      ListNode() : val(0), next(nullptr) {}
      ListNode(int x) : val(x), next(nullptr) {}
     ListNode(int x, ListNode *next) : val(x), next(next) {}
 };

class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode* pnext = reverseList(head->next);
        head->next->next = head;
        head->next = nullptr;
        return pnext;
    }
    void reorderList(ListNode* head) {
        ListNode* slow = head;
        ListNode* fast = slow;
        while (fast && fast->next)
        {
            slow = slow->next;
            fast = fast->next->next;
        }
        ListNode* newhead = reverseList(slow->next);
        slow->next = nullptr;
        ListNode* cur = head;
        while (newhead)
        {

            ListNode* _next = cur->next;
            ListNode* rnext = newhead->next;
            cur->next = newhead;
            newhead->next = _next;
            cur = _next;
            newhead = rnext;
        }
        //if(cur)
    }
};